limsReport.downloadSearchPage = {

    getGridParam : function() {
        var _this = this;
        return {
            type : 'grid',
            id : 'lims-report-download-search-list-grid',
            url : limsReport.baseUrl + '/queries',
            requestData: {
                processStatus_EQ: 'done'
            },
            columns : limsReport.getSearchListColumns(),
            onLoadSuccess : function(data) {
                if (!Gikam.isEmpty(data)) {
                    this.activeRowByIndex(0);
                } else {
                    Gikam.getAsyncComp('lims-report-uploader-download-search').done(function (grid) {
                        grid.setOptions({
                            bizId: -1
                        })
                    });
                }
            },
            onRowActive : function(index, row) {
                Gikam.getAsyncComp('lims-report-uploader-download-search').done(function (grid) {
                    grid.setOptions({
                        bizId: row.id
                    })
                });
            },
            page: true,
            toolbar: [{
                type: 'button',
                text: 'GIKAM.REPORT.ONLINE.VIEW',
                icon: 'preview',
                onClick: function () {
                    var grid = Gikam.getComp('lims-report-download-search-list-grid');
                    var selections = grid.getSelections();
                    if (Gikam.isEmpty(selections)) {
                        Gikam.alert('GIKAM.TIP.CHOOSE_AT_LEAST_ONE_ITEM');
                        return;
                    }
                    window.open(limsReport.baseUrl + '/preview-online/reports' + Gikam.param({
                        ids: selections.map(function (item) {
                            return item.id;
                        }).join(',')
                    }));
                }
            }, {
                type: 'button',
                text: 'GIKAM.TITLE.REPORT.DOWNLOAD',
                icon: 'export',
                onClick: function () {
                    limsReport.downloadReport('lims-report-download-search-list-grid');
                }
            }]
        }
    },

    getBaseInfoTab : function() {
        var _this = this;
        return {
            type : 'tab',
            panels : [ {
                title: 'GIKAM.FILE.ATTACHMENT',
                items: [{
                    type: 'uploader',
                    id: 'lims-report-uploader-download-search',
                    dbTable: 'T_LIMS_REPORT',
                    readonly: true
                }]
            } ]
        }
    },

    create : function() {
        var _this = this;
        Gikam.create('layout', {
            id : 'lims-report-download-search-list-layout',
            renderTo : workspace.window.$dom,
            north : {
                height : '60%',
                items : [ this.getGridParam() ]
            },
            center : {
                items : [ this.getBaseInfoTab() ]
            }
        });
    },

    init : function() {
        this.create();
    }
};
